//
//  LanguageManager.swift
//  Easepods
//
//  Created by 易先生 on 2024/5/7.
//

import UIKit

open class LanguageManager {
    
    public static var language: LanguageCodeEnum {
        
        guard let languageCode = Bundle.main.preferredLocalizations.first else {
            return .en
        }
        
        guard let language = LanguageCodeEnum(rawValue: languageCode) else {
            
            #if DEBUG
            Swift.fatalError("请扩展 LanguageCodeEnum 语言集")
            #endif
            return .en
        }
        return language
    }
    
}


public enum LanguageCodeEnum: String, CaseIterable {
    
    case zh = "zh-Hans"
    case zh_HK = "zh-HK"
    case zh_Hant = "zh-Hant"
    case en = "en"
    case en_US = "en-US"
    case bg = "bg"
    case cs = "cs"
    case da = "da"
    case de = "de"
    case el = "el"
    case el_GR = "el-GR"
    case es = "es"
    case fa = "fa"
    case fi = "fi"
    case fr = "fr"
    case ar = "ar"
    case he = "he"
    case hi = "hi"
    case hr = "hr"
    case hu = "hu"
    case id = "id"
    case it = "it"
    case ja = "ja"
    case ko = "ko"
    case ms = "ms"
    case nb = "nb"
    case nl = "nl"
    case pl = "pl"
    case ps = "ps"
    case pt = "pt"
    case pt_PT = "pt-PT"
    case ro = "ro"
    case ru = "ru"
    case sk = "sk"
    case sl = "sl"
    case sv = "sv"
    case th = "th"
    case tr = "tr"
    case uk = "uk"
    case vi = "vi"
   
    
    public var identifier: String {
        return self.rawValue
    }
    
    public var i18nIdentifier: String {
        
        switch self {
        case .zh:
            return "zh"
            
        case .zh_Hant:
            return "zh-TW"
            
        case .he:
            return "iw"
            
        default:
            return self.identifier
            
        }
    }
    
    public var APIIdentifier: String {
        
        switch self {
        case .zh:
            return "zh-CN"
        case .zh_HK:
            return "zh-TW"
        case .zh_Hant:
            return "zh-TW"
        case .en_US:
            return LanguageCodeEnum.en.identifier
        default:
            return self.identifier
        }
        
    }
    
    public var APIBaseIdentifier: String {
        
        return "en"
        
    }
    
    public var languageName: String {
        switch self {
        case .zh:
            return "简体中文"
        case .zh_HK:
            return "繁体中文"
        case .zh_Hant:
            return "繁体中文"
        case .en:
            return "英文"
        case .en_US:
            return "英文"
        case .bg:
            return "保加利亚语"
        case .cs:
            return "捷克语"
        case .da:
            return "丹麦语"
        case .de:
            return "德语"
        case .el:
            return "希腊语"
        case .el_GR:
            return "希腊语"
        case .es:
            return "西班牙语"
        case .fa:
            return "波斯语"
        case .fi:
            return "芬兰语"
        case .fr:
            return "法语"
        case .ar:
            return "阿拉伯语"
        case .he:
            return "希伯来语"
        case .hi:
            return "印地语"
        case .hr:
            return "克罗地亚语"
        case .hu:
            return "匈牙利语"
        case .id:
            return "印尼语"
        case .it:
            return "意大利语"
        case .ja:
            return "日语"
        case .ko:
            return "韩语"
        case .ms:
            return "马来语"
        case .nb:
            return "挪威语"
        case .nl:
            return "荷兰语"
        case .pl:
            return "波兰语"
        case .ps:
            return "普什图语"
        case .pt:
            return "葡萄牙语"
        case .pt_PT:
            return "葡萄牙语"
        case .ro:
            return "罗马尼亚语"
        case .ru:
            return "俄语"
        case .sk:
            return "斯洛伐克语"
        case .sl:
            return "斯洛文尼亚语"
        case .sv:
            return "瑞典语"
        case .th:
            return "泰语"
        case .tr:
            return "土耳其语"
        case .uk:
            return "乌克兰语"
        case .vi:
            return "越南语"
        }
    }
    

}
